const fs = require('fs');
const db = require('./db');

const files = fs.readdirSync(`${__dirname}/models`);

const js_files = files.filter(f => f.endsWith('.js'), files);

module.exports = {};
for (const f of js_files) {
  console.log(`import model from file ${f}...`);
  const name = f.substring(0, f.length - 3);
  console.log(name);
  module.exports[name] = require(`${__dirname}/models/${f}`);
}


module.exports.sync = () => {
  db.sync();
};

module.exports.query = (sql) => {
  return db.query(sql);
};
